package com.qing.reflection;

//创建Class类的几种方式
public class CreateClass {
    public static void main(String[] args) throws ClassNotFoundException {
        Student student = new Student();
        System.out.println(student.name);

        //方式1：通过对象.getClass获得
        Class c1 = student.getClass();
        System.out.println(c1.hashCode());

        //方式2：通过forName获得(值为类的包路径)
        Class c2 = Class.forName("com.qing.reflection.Student");
        System.out.println(c2.hashCode());

        //方式3：通过类型.class获得
        Class c3 = Student.class;
        System.out.println(c3.hashCode());

        //方式4：基本内置类型会有一个属性TYPE
        Class c4 = Integer.TYPE;
        System.out.println(c4.hashCode());

        //获得父类类型
        Class superclass = c1.getSuperclass();
        System.out.println(superclass);
    }
}

class Person {
    public String name;

    public Person() {
    }

    public Person(String name) {
        this.name = name;
    }
}

class Teacher extends Person{
    public Teacher() {
        this.name = "老师";
    }
}
class Student extends Person{
    public Student(){
        this.name = "学生";
    }
}